﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace WpfHostBuilder
{
    public static class HostingWpfExtensions
    {
        public static IHostBuilder UseWPF<TBootStrapper>(this IHostBuilder hostBuilder)
            where TBootStrapper : AppBootStrapper, new()
        {
            return hostBuilder.ConfigureServices(ser =>
            {
                ser.AddHostedService<TBootStrapper>();
            });
        }

        /// <summary>
        /// Stop the host synchronously.
        /// </summary>
        /// <param name="host">The <see cref="IHost"/> to stop.</param>
        public static void Stop(this IHost host)
        {
            host.StopAsync().GetAwaiter().GetResult();
        }
    }
}